/**
 * 反馈
 */
var localStoragerManager = require('script/localStorageManagers.js');
var mobileFrame = require('scripts/Core/MobileFrame.js');
mui.init({
	swipeBack: true
});
//加载plusReady
if (window.plus) {
	plusReady();
} else {
	document.addEventListener("plusready", plusReady, false);
}
//plusReady
function plusReady() {
	//设置用户名
	var self = plus.webview.currentWebview();
	document.getElementById('feedcontent').value = self.username;
	//保存
	mui('header').on('tap', '#savefeedbtn', updateUsername);
}
//updateUsername
function updateUsername() {
	if(!mobileFrame.IsNetWorkCanUse())return;
	var feedContent = document.getElementById('feedcontent').value;
	if (feedContent.length == 0) {
		mui.toast("用户姓名不能为空");
		return;
	}
	if (feedContent.length > 5) {
		mui.toast("最多不超过5个字！");
		return;
	}
	var userid = localStoragerManager.getUseridSession();
	var url = serverAjax + "/mobile/user/updateUserinfo.do";
	var w = plus.nativeUI.showWaiting();
	mui.ajax(url, {
		data: {
			username: feedContent,
			userid: userid
		},
		type: 'post',
		dataType: 'json',
		timeout: 10000,
		success: function(data) {
			w.close();
			if (data != null) {
				localStoragerManager.setUserinfoSession(data.ext1);
				var parentWebView = plus.webview.getWebviewById("setup/setupindex");
	            parentWebView.evalJS("setUsername('" + feedContent + "')");
	            var selfcenter=plus.webview.getWebviewById('selfcenter/selfindex.html');
					selfcenter.evalJS("setUsername('"+feedContent+"')");
				mui.toast('您的姓名已经修改成功');
				mui.back();
			}
		},
		error: function(e1, e2, e3) {
			w.close();
			ajaxErrorTip();
			console.log(e1);
		}
	});
}